class Solution {
public:
    int majorityElement(vector<int>& nums) {
        int retnum = -1;
        int count = 0;
        for (const auto& num : nums)
        {
            if (count == 0)
                retnum = num;
            if (num == retnum)
                count++;
            else
                count--;
        }
        count = 0;
        for (const auto& num : nums)
        {
            if (retnum == num)
                count++;
        }
        return count * 2 > nums.size() ? retnum : -1;
    }
};